package com.google.appengine.a4ieve;

import com.google.appengine.a4ieve.entities.StudentWrapper;
import com.google.appengine.api.datastore.Entity;

import java.util.List;

public final class Students {

    private static final int COLUMNS = 4;

    public static String render(List<Entity> students) {
        StringBuilder output = new StringBuilder("<tr><td align=\"center\"><span class=\"acheivement-title\">" +
                "Choose students for achievement</span>" +
                "</td></tr><tr><td align=\"center\" padding-left=\"5px\" " +
                "class=\"acheivement-editorLabel\">");
        int count = 0;
        for (Entity student : students) {
            output.append("<input type=\"checkbox\" value=\"").append(student.getProperty(StudentWrapper.USER_ID_PROPERTY))
                    .append("\">")
                    .append(student.getProperty(StudentWrapper.STUDENT_NAME_PROPERTY)).append("</input>");
            count++;
            if (count == COLUMNS) {
                output.append("</td></tr>");
                count = 0;
                output.append("<tr><td align=\"center\" padding-left=\"5px\" class=\"acheivement-editorLabel\">");
            }
        }
        if (count != 0) {
            output.append("</td></tr>");
        }
        return output.toString();
    }
}
